| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- // app/api/branches/[branch]/[year]/months/route.js
- import { NextResponse } from "next/server";
- import { listMonths } from "@/lib/storage";
- import { getSession } from "@/lib/auth/session";
- import { canAccessBranch } from "@/lib/auth/permissions";
- /**
- * GET /api/branches/[branch]/[year]/months
- */
- export async function GET(request, ctx) {
- const session = await getSession();
- if (!session) {
- return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
- }
- const { branch, year } = await ctx.params;
- console.log("[/api/branches/[branch]/[year]/months] params:", {
- branch,
- year,
- });
- if (!branch || !year) {
- return NextResponse.json(
- { error: "branch oder year fehlt" },
- { status: 400 }
- );
- }
- if (!canAccessBranch(session, branch)) {
- return NextResponse.json({ error: "Forbidden" }, { status: 403 });
- }
- try {
- const months = await listMonths(branch, year);
- return NextResponse.json({ branch, year, months });
- } catch (error) {
- console.error("[/api/branches/[branch]/[year]/months] Error:", error);
- return NextResponse.json(
- { error: "Fehler beim Lesen der Monate: " + error.message },
- { status: 500 }
- );
- }
- }
|